home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pnl002.zip / PNL002.TXT < prev    next >
Text File  |  1990-05-17  |  55KB  |  2,179 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.                             
  14.                                                      
  15.                                                                  
  16.                                                                  
  17.                                 ////////    //    //    //   
  18.                                //    //    ///   //    //    
  19.                               //    //    ////  //    //     
  20.                              ////////    // // //    //      
  21.                             //          //  ////    //       
  22.                            //          //   ///    //          
  23.                           //          //    //    ///////    
  24.                                                                  
  25.                                                                  
  26.                                                              
  27.                                                             
  28.                                                             
  29.                                   Pascal NewsLetter         
  30.                                        Issue #2              
  31.                                       May, 1990             
  32.                                                             
  33.                                                             
  34.                                   Editor: Pete Davis         
  35.                                                             
  36.                                                             
  37.                                                             
  38.                                                             
  39.                                                             
  40.                                                             
  41.                                                             
  42.                                                             
  43.                                                             
  44.                                                             
  45.                                                             
  46.                                                             
  47.                                                                 
  48.                     The Programmer's Forum BBS is the home of
  49.                     PNL. It can be reached in Washington, DC at
  50.                     (202)966-3647. Information is available 
  51.                     through the following locations:        
  52.                                                             
  53.                     FidoNet: Pete Davis@1:109/138           
  54.                     GEnie: P.DAVIS5                          
  55.                     BitNet: HJ647C@GWUVM & UE356C@GWUVM
  56.                     InterNet:
  57.                     HJ647C@GWUVM.GWU.EDU & 
  58.                     UE356C@GWUVM.GWU.EDU
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.                                   Table of Contents
  76.  
  77.           Introduction ........................... Page 3  (Pete Davis)
  78.           Making the Point with Pointers ......... Page 5  (Pete Davis)
  79.           Neat Use of Object Files ............... Page 16 (Craig Thurber)
  80.           For Beginners .......................... Page 22 (Bob Gowans)
  81.           Conclusion ............................. Page 29 (Pete Davis)
  82.           Notice ................................. Page 32 (Pete Davis)
  83.           Distribution List ...................... Page 33 (Pete Davis)
  84.  
  85.  
  86.  
  87.  
  88.           Turbo Pascal is a registered trademark of Borland International
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.                                                                           2
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.                                      Introduction
  140.  
  141.  
  142.  
  143.                Well,  school is over and it's time  for the second issue of
  144.  
  145.           PNL. I would first like to thank Robert  Garcia in Edinburgh (did
  146.  
  147.           I spell that  right?) Texas. He was the first person to give me a
  148.  
  149.           response. His praise alone would have  been enough for the second
  150.  
  151.           issue to  come out. He  also gave me  the idea for an  article on
  152.  
  153.           pointers for beginners.  I had  overlooked that, so  here it  is.
  154.  
  155.           Secondly, I  would like  to thank  Craig Thurber,  the author  of
  156.  
  157.           'Neat Use of Object Files' and Bob Gowans, the author of the 'For
  158.  
  159.           Beginners'  column.  I  really  liked  the articles  and  learned
  160.  
  161.           something new. Thanks Craig and Bob,  feel free to contribute any
  162.  
  163.           time. 
  164.  
  165.  
  166.  
  167.                I  would  like  to  point  out  that  I am  really  open  to
  168.  
  169.           submissions.  Please, if you write  an article, send  it to us. I
  170.  
  171.           can't guarantee when  or if it will  go in, but it  can't hurt to
  172.  
  173.           try. It takes some of the load off of my shoulders.
  174.  
  175.  
  176.  
  177.                One subject that I would really  like to see covered in PNL,
  178.  
  179.           is  Object Oriented  Programming  in Turbo  Pascal.  This is  one
  180.  
  181.           subject I will have to leave to others, at least for now, as I am
  182.  
  183.           not really  fluent in it yet. So, if  you're a hot-shot with OOP,
  184.  
  185.           please submit an article. It would be very beneficial to a lot of
  186.  
  187.           people, including me.
  188.  
  189.  
  190.  
  191.  
  192.                                                                           3
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.                I would really just  like to thank everyone that  I've heard
  206.  
  207.           from. Your compliments, suggestions, and  comments are what makes
  208.  
  209.           this worth doing. I hope to have the PNL going for as long as I'm
  210.  
  211.           computing.
  212.  
  213.  
  214.  
  215.                Oh yeah, and one last thing.  The release of PNL might be  a
  216.  
  217.           little sporadic. Maybe after a while I'll start setting some kind
  218.  
  219.           of time  period up, but right now, it's  whenever I get the time.
  220.  
  221.           I'm hoping to  be able to do  it more than once a  month, if time
  222.  
  223.           allows. I really do enjoy writing this.
  224.  
  225.  
  226.  
  227.                Well, until the next issue, thanks,  and please try to pitch
  228.  
  229.           in:  be it an  article, a suggestion,  or just passing  this file
  230.  
  231.           around to your local bulletin board. All of this helps.
  232.  
  233.  
  234.  
  235.                                                  _Pete Davis
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.                                                                           4
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.                             Making the Point with Pointers
  272.  
  273.  
  274.  
  275.                Those of you familiar  with C are probably very  comfortable
  276.  
  277.           with  pointers.  That's understandable,  you  can't program  in C
  278.  
  279.           without pointers (well, you can, but not well). Well, those of us
  280.  
  281.           that started on  Pascal have a little  more trouble understanding
  282.  
  283.           them. Part of the problem is that pointers seem almost foreign to
  284.  
  285.           the ideas and  methods of programming  in Pascal. In fact,  until
  286.  
  287.           getting involved in  more advanced  programming, one can  usually
  288.  
  289.           get away without  using pointers  at all. So,  why use  pointers?
  290.  
  291.           Well, there  are  several reasons.  For  one, and  probably  most
  292.  
  293.           important, it gives you access to the heap, all that extra memory
  294.  
  295.           you have in a 640K machine that  you normally can't use. In Turbo
  296.  
  297.           Pascal, you are  limited to  64k for any  single data  structure.
  298.  
  299.           This is a  pretty severe  limitation when you  are working  with,
  300.  
  301.           say, a database, or a word processor. Secondly, there are quite a
  302.  
  303.           few  structures that  are  more difficult  to  work with  without
  304.  
  305.           pointers, for example, a binary tree.
  306.  
  307.  
  308.  
  309.                There  are  a  multitude of  structures  that  pointers make
  310.  
  311.           possible.  Covering every  single  one of  them  would be  almost
  312.  
  313.           impossible. To make things a little more reasonable, I will cover
  314.  
  315.           the basic concept  of pointers, and then  the most common use  of
  316.  
  317.           them: The linked list. I will  leave coverage of other structures
  318.  
  319.           to  future  releases of  PNL. In  PNL001,  there was  an article:
  320.  
  321.           Generic Structures in Turbo Pascal, which covered a simple stack,
  322.  
  323.  
  324.                                                                           5
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.           using pointers. It  was a  more complicated version  of a  stack,
  338.  
  339.           actually, but the same ideas prevail for other structures. I will
  340.  
  341.           present a linked list with several operators. I will also include
  342.  
  343.           source code  to  the Linked  List  unit itself  and then  in  the
  344.  
  345.           article on  Sorting,  I will  include  some sorting  routines  to
  346.  
  347.           manipulate our linked list.
  348.  
  349.  
  350.  
  351.                Think of a  linked list as a  chain. Each link in  the chain
  352.  
  353.           contains some data.  At the end of that link is another link with
  354.  
  355.           more  data. You can add links to your chain and you can take them
  356.  
  357.           off. If  you take  a  link out  of the  middle, you  have to  re-
  358.  
  359.           connect your two chains to make a single chain. This is the basic
  360.  
  361.           premise for linked  lists. Depending  on how you  want your  data
  362.  
  363.           ordered (if you even want it ordered) decides how you insert your
  364.  
  365.           data. If you want a stack, you always add a link at the beginning
  366.  
  367.           of your chain. If you want a  queue, you always add a link at the
  368.  
  369.           end of  your chain. If  you want  a non-ordered linked  list, you
  370.  
  371.           could do either. If you want an ordered linked  list, though, you
  372.  
  373.           have to go through your list, find  out where your link goes, and
  374.  
  375.           insert it between  two other  links. (unless it's  the lowest  or
  376.  
  377.           highest value in the list)
  378.  
  379.  
  380.  
  381.                Below is a small diagram of a linked list. Following it is a
  382.  
  383.           short explanation.
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.                                                                           6
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.              Node 1               Node 2               Node 3
  404.           +----------+         +----------+         +----------+
  405.           |   Data   |    +--->|   Data   |    +--->|   Data   |
  406.           |  Item 1  |    |    |  Item 2  |    |    |  Item 3  |
  407.           +----------+    |    +----------+    |    +----------+
  408.           | Pointer  |----+    | Pointer  |----+    | Pointer  |-->NIL
  409.           +----------+         +----------+         +----------+
  410.  
  411.                Each node  in our  list contains  two things:  A Data  Item,
  412.  
  413.           which  the  programmer can  decide  on:  A record,  a  string, an
  414.  
  415.           integer,  etc.. Any  data  type will  do.  The second  item is  a
  416.  
  417.           pointer. The pointer points to the location in memory of the next
  418.  
  419.           node in the  list. The two nodes  don't have to be  anywhere near
  420.  
  421.           each other in memory, but as a programmer, they will appear to be
  422.  
  423.           right next to each-other. Notice the  NIL in the pointer in  Node
  424.  
  425.           3. This is  a reserved value  in pascal  that indicates that  the
  426.  
  427.           pointer is pointing to nothing. In our case, it signifies the end
  428.  
  429.           of the list. 
  430.  
  431.  
  432.  
  433.                Now, we are  missing one item in  our list, and that  is the
  434.  
  435.           pointer to the beginning of the  list. This is something that you
  436.  
  437.           must have, otherwise you won't know where in memory your list is.
  438.  
  439.           First, let's create our sample record and pointer:
  440.  
  441.  
  442.  
  443.  
  444.           type 
  445.             Samp_Ptr = ^Samp_Rec;      { A pointer to a Samp_Rec record }
  446.             Samp_Rec = record          { Our Samp_Rec record type       }
  447.                SampData : integer;     { Data can really be anything    }
  448.                Next_Rec : Samp_Ptr;    { Pointer to next item in list   }
  449.             end;
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.                                                                           7
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.                Ok, Samp_Ptr is a pointer to data of type Samp_Rec. You make
  470.  
  471.           a typed pointer by  including the '^'  before the data type  that
  472.  
  473.           you want to point to; in this case Samp_Rec. Notice that Samp_Ptr
  474.  
  475.           is declared before  Samp_Rec, yet Samp_Ptr  is a pointer to  type
  476.  
  477.           Samp_Rec. The reason for this is so that the Next_Rec pointer can
  478.  
  479.           be declared, making linked lists possible.
  480.  
  481.  
  482.  
  483.                Now, to help give us  something to work with, I'll  show the
  484.  
  485.           initialization  procedure, and then go into  a bit of explanation
  486.  
  487.           about how it works.
  488.  
  489.  
  490.           procedure Init_Samp_List(var Head : Samp_Ptr);
  491.  
  492.           { notice in our initialization that a record of type Samp_Rec is 
  493.            never defined nor used!                                       }
  494.            
  495.           begin
  496.             Head := nil;
  497.           end;
  498.  
  499.  
  500.                First  of all,  notice  that in  our  initialization we  are
  501.  
  502.           passing a pointer of type Samp_Ptr, and  not an actual record. It
  503.  
  504.           must also be passed as a variable parameter, as the variable Head
  505.  
  506.           will be given it's  initial value and that  value must return  to
  507.  
  508.           the  main program. The  only code in this  procedure is to assign
  509.  
  510.           the pascal reserved value of nil to Head. Head means the  head of
  511.  
  512.           the list, or the first link  in the list. nil is a  variable name
  513.  
  514.           supplied by pascal which  means that there is not  value assigned
  515.  
  516.           to the variable. In our case, it means that our list is empty.
  517.  
  518.  
  519.  
  520.  
  521.  
  522.                                                                           8
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.                Now, I want to supply a simple  insert procedure to insert a
  536.  
  537.           single value into the list. This will give us a little picture of
  538.  
  539.           how to manipulate our data with  pointers. The insert procedure I
  540.  
  541.           am providing here inserts a value into the beginning of the list.
  542.  
  543.           In the Turbo  Pascal Unit, enclosed,  you will find three  insert
  544.  
  545.           procedures: Insert_End, Insert_Begin,  and Insert_In_Order.  I'll
  546.  
  547.           leave Insert_Before, and Insert_After for you to write. They  way
  548.  
  549.           they are supposed  to work  is that Insert_Before  will insert  a
  550.  
  551.           record right in front of the  current record you are pointing to.
  552.  
  553.           To accomplish this, you need to pass  two items: The head, so you
  554.  
  555.           can go  through the  list again to  find out  what the  record is
  556.  
  557.           before  the current  record, and  the current record,  of course.
  558.  
  559.           Insert_After is a  little easier, in all that  needs to be passed
  560.  
  561.           is  the  current record.  The  record  you insert  should  end up
  562.  
  563.           pointing to the record  that was right after the  current record,
  564.  
  565.           and  the current  record should  end up pointing  to the  one you
  566.  
  567.           insert.  One  would rarely need  this many insert procedures,  in
  568.  
  569.           fact,  one  is  usually  enough.  So,  on  with our  Insert_Begin
  570.  
  571.           procedure:
  572.  
  573.  
  574.  
  575.           procedure Insert_Begin(var Head : Samp_Ptr; 
  576.                                Data_Value : integer);
  577.  
  578.           var
  579.             Temp : Samp_Ptr;  { A temporary variable to work with }
  580.  
  581.           begin
  582.             { Allocate memory for a Samp_Ptr }
  583.             new(Temp);                
  584.  
  585.  
  586.  
  587.  
  588.                                                                           9
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.             { Temp will become the first record and Head will become 
  602.               the second record in the list. But, we have to do things
  603.               kind of backwards, so first: Make head the second record }
  604.             Temp^.Next_Rec := Head;   
  605.  
  606.             { Now that Temp^.Next_Rec has a pointer to where the second
  607.               record is, we can now change the value of Head so that it
  608.               will be at the head of the list.                          }
  609.             Head:= Temp;
  610.  
  611.             { Next we need to put the value in this first record, that 
  612.               the user has provided to us.                              }
  613.             Head^.SampData := Data_Value;
  614.           end; {All done}
  615.  
  616.  
  617.                Here's what's going  on: First  of all, the  new command  is
  618.  
  619.           used to allocate  some space on  the heap for  our data. The  new
  620.  
  621.           procedure  returns  the  memory  location of  this  space  in the
  622.  
  623.           variable Temp. Instead of directly using a Samp_Rec data type, we
  624.  
  625.           use the  pointers  Temp and  Head  to access  the  fields in  our
  626.  
  627.           reserved space. To do this, the general construct is:
  628.  
  629.             POINTER^.FIELDNAME
  630.  
  631.  
  632.  
  633.                One can assign  something to this  place or receive a  value
  634.  
  635.           already stored. For example, to find the contents of SampData for
  636.  
  637.           the first record in the  list we could do the  following. (Assume
  638.  
  639.           that OurInt was previously defined as an integer.)
  640.  
  641.           OurInt := Head^.SampData;
  642.  
  643.           or we could change the contents by writing:
  644.  
  645.           Head^.SampData := OurInt;
  646.  
  647.  
  648.  
  649.                The most important step  and the one that seems to cause the
  650.  
  651.           most  problems  for  programmers  unfamiliar  with  pointers,  is
  652.  
  653.  
  654.                                                                          10
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.           maintaining and traversing the links in our list. Noticed what we
  668.  
  669.           did in  our Insert_Begin procedure - If we  are using a new list,
  670.  
  671.           then Head is going to have a value of nil :
  672.  
  673.  
  674.  
  675.           Head-> Nil
  676.  
  677.                First of all,  we allocate  some memory for  the record  and
  678.  
  679.           then assign the value of head to Temp^.Next_Rec :
  680.  
  681.  
  682.                   +----------+
  683.                   | SampData |
  684.           Temp -> | undefined|     
  685.                   +----------+     
  686.                   | Next_Rec |
  687.                   |   Nil    | 
  688.                   +----------+
  689.  
  690.  
  691.                Next we assigned Head to be equal to Temp:
  692.  
  693.  
  694.                   +----------+
  695.           Head -> | SampData |
  696.           Temp -> | undefined|     
  697.                   +----------+     
  698.                   | Next_Rec |
  699.                   |   Nil    | 
  700.                   +----------+
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.                After that, we had to assign the value to SampData. Suppose
  708.  
  709.           we passed the value of 4:
  710.  
  711.  
  712.                   +----------+
  713.           Head -> | SampData |
  714.           Temp -> |    4     |     
  715.                   +----------+     
  716.                   | Next_Rec |
  717.                   |   Nil    | 
  718.                   +----------+
  719.  
  720.                                                                          11
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.                That  takes  care of  our first  value,  but what  about the
  734.  
  735.           second  value? How does  that work? Well,  if we follow  the same
  736.  
  737.           steps as before, let's  see where it leaves  us. Let's say  we're
  738.  
  739.           going to insert a value of 12 this  time. First of all we need to
  740.  
  741.           allocate space and Temp  will be pointing to that  space, then we
  742.  
  743.           assign Temp^.Next_Rec to Head:
  744.  
  745.  
  746.                   +----------+            +----------+
  747.                   | SampData |            | SampData |
  748.           Temp -> | undefined|    +-----> |    4     |
  749.                   +----------+    |       +----------+
  750.                   | Next_Rec |    |       | Next_Rec |
  751.                   |   Head   |----+       |   Nil    |
  752.                   +----------+            +----------+
  753.  
  754.  
  755.                Now, we assign the value of Head = Temp. That will move Head
  756.  
  757.           to the beginning of the list.
  758.  
  759.  
  760.                   +----------+            +----------+
  761.           Head -> | SampData |            | SampData |
  762.           Temp -> | undefined|    +-----> |    4     |
  763.                   +----------+    |       +----------+
  764.                   | Next_Rec |    |       | Next_Rec |
  765.                   |   -------|----+       |   Nil    |
  766.                   +----------+            +----------+
  767.  
  768.  
  769.                Now we assign the value of Data_Value (12) to the SampData
  770.  
  771.           field.
  772.  
  773.  
  774.  
  775.                   +----------+            +----------+
  776.           Head -> | SampData |            | SampData |
  777.           Temp -> |    12    |    +-----> |    4     |
  778.                   +----------+    |       +----------+
  779.                   | Next_Rec |    |       | Next_Rec |
  780.                   |   -------|----+       |   Nil    |
  781.                   +----------+            +----------+
  782.  
  783.  
  784.  
  785.  
  786.                                                                          12
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.                That just about  does it  for the insert  procedure. It's  a
  800.  
  801.           very difficult concept for beginners to understand and that's why
  802.  
  803.           I am supplying all of the diagrams. I want to make the concept of
  804.  
  805.           pointers themselves as clear as possible. Once you understand the
  806.  
  807.           concept, the different operations on them become easy. If at this
  808.  
  809.           point you still don't understand, I  suggest that you reread from
  810.  
  811.           the top of the article and give it another try.  If at that point
  812.  
  813.           you still don't understand, try putting it away for a day  or two
  814.  
  815.           and try again. I find that putting a difficult concept away for a
  816.  
  817.           little while and coming back to it makes it easier to understand.
  818.  
  819.  
  820.  
  821.                Like the insert  operations, the  delete operations come  in
  822.  
  823.           all  shapes  and  sizes.  The   accompanying  unit  contains  the
  824.  
  825.           following: Pop_First  (for stack  use),  Pop_Last(for queue)  and
  826.  
  827.           Delete_Here. Again, I will  leave Delete_Before and  Delete_After
  828.  
  829.           for you to write.  With the three I provide, it  should be fairly
  830.  
  831.           simple. These are more  than enough for the typical  linked list.
  832.  
  833.           The main problem with doing the  delete is that you have to  find
  834.  
  835.           out where you are in the list before you can take any action.  If
  836.  
  837.           you want to delete the first node  in the list, then you have  to
  838.  
  839.           re-assign the Head of the list to the second item in the list. If
  840.  
  841.           you want to delete  something from the end of the  list, you need
  842.  
  843.           to  make sure that the  Next_Rec field is set to  Nil in the last
  844.  
  845.           record. If you want to delete something in the middle of the list
  846.  
  847.           then you have to  reconnect to second half of the  list to what's
  848.  
  849.           left of the first half.
  850.  
  851.  
  852.                                                                          13
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.           Using our first diagram:
  866.  
  867.  
  868.              Node 1               Node 2               Node 3
  869.           +----------+         +----------+         +----------+
  870.           |   Data   |    +--->|   Data   |    +--->|   Data   |
  871.           |  Item 1  |    |    |  Item 2  |    |    |  Item 3  |
  872.           +----------+    |    +----------+    |    +----------+
  873.           | Pointer  |----+    | Pointer  |----+    | Pointer  |-->NIL
  874.           +----------+         +----------+         +----------+
  875.  
  876.                If we take out Node 2, we have to assign the pointer in Node
  877.  
  878.           1 to point to  Node 3. If we get  rid of Node 3, we need  to have
  879.  
  880.           the Pointer in Node 2 be nil. 
  881.  
  882.              Node 1               Node 2               Node 3
  883.           +----------+         +----------+         +----------+
  884.           |   Data   |    X--->|   Data   |    X--->|   Data   |
  885.           |  Item 1  |    X    |  Item 2  |    X +->|  Item 3  |
  886.           +----------+    X    +----------+    X |  +----------+
  887.           | Pointer  |--+-X    | Pointer  |----X |  | Pointer  |-->NIL
  888.           +----------+  |      +----------+      |  +----------+
  889.                         +------------------------+
  890.  
  891.                This brings up the  need for one more procedure  provided in
  892.  
  893.           pascal, and that's  the dispose procedure. The  dispose procedure
  894.  
  895.           returns whatever space  you have  allocated back to  the heap  so
  896.  
  897.           that it can be  reused. You don't always have to  do that, but if
  898.  
  899.           you are  working with  a lot  of data  and you get  rid of  links
  900.  
  901.           without using the dispose  procedure, you are more likely  to run
  902.  
  903.           out of heap memory. I will let you look at the source code for an
  904.  
  905.           example of the dispose procedure.
  906.  
  907.  
  908.  
  909.                I'm going to  have to keep  myself from including more  code
  910.  
  911.           examples in the  magazine, and instead let you  see the unit that
  912.  
  913.           is included with this issue. It  has all the necessary procedures
  914.  
  915.           and  functions, and then  some. Each one has  a description as to
  916.  
  917.  
  918.                                                                          14
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.           it's  function. I don't feel  that further explanation here would
  932.  
  933.           be beneficial. In  other words, I'm out of  breath and thought. I
  934.  
  935.           don't know what else I could tell you.
  936.  
  937.  
  938.  
  939.                I hope this  article has been  helpful, and if anyone  feels
  940.  
  941.           that I've missed something important, I'll do a follow-up article
  942.  
  943.           on it. I will be showing other  uses of pointers in other issues,
  944.  
  945.           but it is unlikely that I will keep it this basic,  unless demand
  946.  
  947.           keeps things at this level.
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.                                                                          15
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.                                NEAT USE OF OBJECT FILES
  998.  
  999.                                   by Craig Thurber 
  1000.  
  1001.            
  1002.  
  1003.                Not  long ago I  wanted to do  something simple:   include a
  1004.  
  1005.           downloadable soft font file in a compiled Pascal .EXE file.  This
  1006.  
  1007.           seemed like  an easy  thing to  do, but  alas, I  could not  find
  1008.  
  1009.           anything in  my documentation  or  reference books  that gave  an
  1010.  
  1011.           indication of how  to do it.   It wasn't long before  some of the
  1012.  
  1013.           fine users of this language pitched  in and provided an answer to
  1014.  
  1015.           the  problem.  The answer  has proven to be a  neat use of object
  1016.  
  1017.           files.  The inclusion of text or other types of files in the .EXE
  1018.  
  1019.           forms has a  number of advantages, the most notable of which is a
  1020.  
  1021.           very quick  access to  what might  otherwise be  a separate  disk
  1022.  
  1023.           file.  Since the  equivalent of the disk  file is already  loaded
  1024.  
  1025.           into memory, there is no need to wait for a floppy disk file to 
  1026.  
  1027.           be accessed. 
  1028.  
  1029.            
  1030.  
  1031.                The  method and  some  examples are  presented below.   Many
  1032.  
  1033.           thanks to Juan  Jimenez for both  his insights into this  problem
  1034.  
  1035.           and his  patients in providing an answer for  which I had no more
  1036.  
  1037.           questions.  Juan answered the message that I posted in  the GEnie
  1038.  
  1039.           Borland  Roundtable.    If you  are  interested  in  a very  fine
  1040.  
  1041.           service, please consider this one*. 
  1042.  
  1043.  
  1044.  
  1045.           External Procedure Calls 
  1046.           ------------------------ 
  1047.  
  1048.                External procedures can be declared and called in the Pascal
  1049.  
  1050.                                                                          16
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.           language.   The  user manual  suggests that  this  capability was
  1064.  
  1065.           included  in  the language  primarily  for inclusion  of assembly
  1066.  
  1067.           language routines in  the compiled  versions of Pascal  programs.
  1068.  
  1069.           However, the call to an external procedure can also be used to 
  1070.  
  1071.           move  the contents  of a  text  or other  type file  to  a Pascal
  1072.  
  1073.           pointer location, and then to  perform standard Pascal operations
  1074.  
  1075.           with the data that resides at that pointer location.  Declaration
  1076.  
  1077.           of  an  external  procedure  call  is  made  with  the  following
  1078.  
  1079.           statement in a Pascal program or unit: 
  1080.  
  1081.  
  1082.  
  1083.           procedure HelloJuan;  external;  {$L HELLO.OBJ} 
  1084.  
  1085.            
  1086.  
  1087.           In the above example, the external file named HELLO.OBJ will be 
  1088.  
  1089.           included in the compilation  of the .EXE file.  The {$L} compiler
  1090.  
  1091.           directive is the  local symbol information directive.   Note that
  1092.  
  1093.           this  compiler  directive  is ignored  if  the  Debug Information
  1094.  
  1095.           setting {$D-} is set to off. 
  1096.  
  1097.            The  overall effect  of  this declaration  is that  the external
  1098.  
  1099.           object file  named HELLO.OBJ is recorded in the .TPU or .EXE file
  1100.  
  1101.           at the time of compilation.  While this inclusion will increase 
  1102.  
  1103.           the size of these files, it does not slow program execution. 
  1104.  
  1105.  
  1106.  
  1107.            Creation of Object Files 
  1108.           ------------------------ 
  1109.  
  1110.           Object files  are  created with  the BINOBJ.EXE  utility that  is
  1111.  
  1112.           provided with  Turbo Pascal.  The procedure involves invoking the
  1113.  
  1114.           BINOBJ.EXE procedures with a designated file for conversion and 
  1115.  
  1116.                                                                          17
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.           an external name to give to the file.  In the case shown above, 
  1130.  
  1131.           the test file  HELLO.TXT would  be converted to  the object  file
  1132.  
  1133.           HELLO.OBJ having the  external procedure call HelloJuan  with the
  1134.  
  1135.           following command (assuming the given drives and directories):  
  1136.  
  1137.             C:\TP\BINOBJ A:\HELLO.TXT A:\HELLO.OBJ HELLOJUAN 
  1138.  
  1139.            
  1140.  
  1141.           When creating object files, keep track of the original file size.
  1142.  
  1143.           You  will need  it  later  when  you  invoke  them  in  a  Pascal
  1144.  
  1145.           procedure. 
  1146.  
  1147.            
  1148.  
  1149.           Using the External Procedure 
  1150.           ---------------------------- 
  1151.  
  1152.                Suppose that you  started by  declaring the above  procedure
  1153.  
  1154.           after converting the file HELLO.TXT to the object file HELLO.OBJ.
  1155.  
  1156.           The original text  file contained  the statement "Hello,  Juan.",
  1157.  
  1158.           which is 13 characters long.  After conversion to an object file,
  1159.  
  1160.           be  sure not to confuse the byte size of the object file with the
  1161.  
  1162.           size  of the original text file;  it  is the size of the original
  1163.  
  1164.           file that you  will need while  writing the Pascal code.  Suppose
  1165.  
  1166.           also  that  the objective  of  your  programming is  to  send the
  1167.  
  1168.           statement  "Hello,  Juan." from  the  compiled .EXE  file  to the
  1169.  
  1170.           printer.   Here is  the code  that will  do this,  as a  complete
  1171.  
  1172.           program.  Each statement in the program is explained below.  
  1173.  
  1174.  
  1175.             program Hello; 
  1176.            
  1177.               uses Printer; 
  1178.            
  1179.               procedure HelloJuan;  external;  {$L+ HELLO.OBJ} 
  1180.            
  1181.  
  1182.                                                                          18
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.                 var PtrStr    : Pointer; 
  1196.                     OutString : String; 
  1197.            
  1198.                 begin 
  1199.                   PtsStr := @HelloJuan; 
  1200.                   Move(PtrStr^,OutStr[1],13); 
  1201.                   OutStr[0] := Chr(11); 
  1202.                   Writeln(Lst,OutStr) 
  1203.                 end. 
  1204.            
  1205.  
  1206.  
  1207.  
  1208.           The  result  of running  this  file  will be  printing  the words
  1209.  
  1210.           "Hello, Juan" on the printer that is located at LPT1. 
  1211.  
  1212.            
  1213.  
  1214.                As nice  a fellow as  Juan is, I  don't suppose that  making
  1215.  
  1216.           your printer say hello to him is very useful to you.   So here is
  1217.  
  1218.           another  example.   Suppose  you want  a full  screen of  text to
  1219.  
  1220.           appear instantly.   You have written programs that make a call to
  1221.  
  1222.           an external file and have watched them slowly write one line at a
  1223.  
  1224.           time  down the screen;  you have  had enough of this and you want
  1225.  
  1226.           the speed that  Pascal normally shows.   Well, this could  be the
  1227.  
  1228.           answer.  Write your text file, note the length of it (I'll use 
  1229.  
  1230.           2000 here) and then change the above program as shown below.  For
  1231.  
  1232.           purposes of this article,  I have assumed that the file names and
  1233.  
  1234.           external declarations are the same;   the only difference is that
  1235.  
  1236.           you are  now writing  a nice letter  to Juan  and you want  it to
  1237.  
  1238.           appear on  the screen very quickly.   Here is the  procedure code
  1239.  
  1240.           that will do it: 
  1241.  
  1242.            
  1243.             procedure HelloJuan;  external;  {$L HELLO.OBJ} 
  1244.                 
  1245.               const Size = 2000; 
  1246.            
  1247.  
  1248.                                                                          19
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.               var PtrStr : Pointer; 
  1262.                   OutStr : Array[1..2000] of Char; 
  1263.                   Index  : Integer; 
  1264.            
  1265.               begin 
  1266.                 PtrStr := @HelloJuan; 
  1267.                 Move(PtrStr^,OutStr[1],Size); 
  1268.                 For Index := 1 to Size do 
  1269.                   Write(OutStr[Index]) 
  1270.               end; 
  1271.            
  1272.  
  1273.  
  1274.           What's That Code All About? 
  1275.           --------------------------- 
  1276.  
  1277.           Here is what the coding is all about: 
  1278.  
  1279.            
  1280.  
  1281.                Variable declarations:  PtrStr is a  generic pointer.  It is
  1282.  
  1283.           used to mark the starting location of the compiled external file.
  1284.  
  1285.           OutStr is an array  that is large enough to hold  the contents of
  1286.  
  1287.           the externally  declared procedure.   Index is  a simple  counter
  1288.  
  1289.           that is  used  to track  the  feeding of  each character  of  the
  1290.  
  1291.           compiled external file to the screen. 
  1292.  
  1293.            
  1294.  
  1295.                PtrStr := @HelloJuan; :  This statement moves the pointer to
  1296.  
  1297.  
  1298.  
  1299.           The start of  the procedure that  was named HelloJuan during  the
  1300.  
  1301.           conversion of the text file to an object file. 
  1302.  
  1303.  
  1304.  
  1305.                Move(PtrStr^,OutStr[1],Size);:    This  statement moves  the
  1306.  
  1307.           number  of bytes  specified by  Size from  the starting  location
  1308.  
  1309.           specified by PtrStr^ to the first element of the array OutStr.  
  1310.  
  1311.            
  1312.  
  1313.  
  1314.                                                                          20
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.                For Index ... do  : This loop dumps the array  OutStr to the
  1328.  
  1329.           screen  one element at  a time.   The resulting screen  dump will
  1330.  
  1331.           appear exactly as the original text file was written.   
  1332.  
  1333.            
  1334.  
  1335.           What Else Does It Do? 
  1336.           --------------------- 
  1337.  
  1338.                The  conversion of files  to object  files and  inclusion of
  1339.  
  1340.           them in the executable form of a program offers a wide variety of
  1341.  
  1342.           opportunities for programmers.   In principle, any file  that you
  1343.  
  1344.           can present  on  the screen  or printer  can be  converted to  an
  1345.  
  1346.           object  file   and  then  included   in  the  .EXE   file  during
  1347.  
  1348.           compilation.   When  the  procedure  is  called using  the  above
  1349.  
  1350.           techniques,  the results will be very  quick and will be an exact
  1351.  
  1352.           duplicate of what you would get by  other means.  So if you  want
  1353.  
  1354.           to have  a fast way  of accessing  help files, graphics  or other
  1355.  
  1356.           files, give the method a try.  
  1357.  
  1358.            
  1359.  
  1360.           * A GEnie account can be obtained by calling 1-800-638-9636.
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.                                                                          21
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.                                     For Beginners
  1394.  
  1395.                                     By Bob Gowans
  1396.  
  1397.             
  1398.  
  1399.                Where to start? A  good question - the beginner's  column is
  1400.  
  1401.           aimed  at  people with  little or  no   programing  experience of
  1402.  
  1403.           Pascal  and  will start at  a very basic  level but will graduate
  1404.  
  1405.           (hopefully) to  more  complicated  programming  routines  as  our
  1406.  
  1407.           confidence in  the use of Pascal increases. With  this in  mind I
  1408.  
  1409.           would  appreciate  any  feedback on  my  articles  - suggestions,
  1410.  
  1411.           constructive criticism and especially  any neat programing tricks
  1412.  
  1413.           that beginners would find useful. I will give details on  contact
  1414.  
  1415.           addresses at the end of this article.   
  1416.  
  1417.  
  1418.  
  1419.                Pascal  has  to be  taught  in  a way  that  encourages good
  1420.  
  1421.           programing. As  a high-level  language it  is structured  in this
  1422.  
  1423.           way and can allow the Pascal programer to present his programs in
  1424.  
  1425.           a  manner  of  clarity  that  is  almost  unparalleled  by  other
  1426.  
  1427.           high-level  languages. So  if  you have  just  bought the  latest
  1428.  
  1429.           version of  your favorite  Pascal compiler  and your fingers  are
  1430.  
  1431.           itching to  get at the keyboard  to write that ultra  program you
  1432.  
  1433.           have always  wanted to  produce to  impress  your friends,  wife,
  1434.  
  1435.           boss?  Then  stop!  Good  programs  take  a lot  of  thought  and
  1436.  
  1437.           planning before you  reach the actual  coding stage. In fact,  an
  1438.  
  1439.           English  language  equivalent  of your  program  should  first be
  1440.  
  1441.           produced, showing  step by step what your  program does. Moreover
  1442.  
  1443.           this English language  version should be  able to make clear,  to
  1444.  
  1445.  
  1446.                                                                          22
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.           non-programers, exactly what  your program is  going to do.  This
  1460.  
  1461.           may not be essential  for the relatively small programs  which we
  1462.  
  1463.           will encounter at  this stage but  it is an invaluable  technique
  1464.  
  1465.           when  writing  large  programs  (such  as  the  impressive  ultra
  1466.  
  1467.           program) and   as  an aid to  problem solving.  It is  well worth
  1468.  
  1469.           while  getting  into the  habit  of  using this  method  known as
  1470.  
  1471.           TOP-DOWN design to  plan you programs.  In future articles it  is
  1472.  
  1473.           hoped that  I will be able to introduce this method but meanwhile
  1474.  
  1475.           lets  get back  to those  itching fingers  and get  on with  some
  1476.  
  1477.           program   writing. The  programs given  as examples are  standard
  1478.  
  1479.           Pascal,  that is they  should compile using  any Pascal compiler,
  1480.  
  1481.           however I have only used Turbo Pascal V4 to try them out and test
  1482.  
  1483.           them. Here is a simple but complete Pascal program: 
  1484.  
  1485.             
  1486.           program hello_there;   { This is our first program } 
  1487.           begin 
  1488.              write('Hello'); 
  1489.              writeln(' my name is Bob'); 
  1490.              write('How are you?') 
  1491.           end. 
  1492.             
  1493.  
  1494.                Lets break  this program  down to it's  component parts  and
  1495.  
  1496.           examine  each  part in  turn. The  program  starts with  the word
  1497.  
  1498.           program followed by a space followed by the program name. In this
  1499.  
  1500.           case  the name is hello_there but subject to some rules, it could
  1501.  
  1502.           be anything we chose,  however it is good programing  practice to
  1503.  
  1504.           chose a  name that is  relevant to  what the  program does.  Such
  1505.  
  1506.           names are given the term IDENTIFIERS. 
  1507.  
  1508.           Rules for identifiers: 
  1509.  
  1510.  
  1511.  
  1512.                                                                          23
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.           1) An identifier must begin with a letter. 
  1526.  
  1527.  
  1528.  
  1529.           2)  They  may  then  consist  of  letters and  digits,  upper  or
  1530.  
  1531.           lowercase letters are treated as identical. 
  1532.  
  1533.  
  1534.  
  1535.           3) They  can contain  embedded underscore  characters to  improve
  1536.  
  1537.           readability as has been done in  our example program identifier -
  1538.  
  1539.           hello_there. 
  1540.  
  1541.  
  1542.  
  1543.           4) They can be of any length but generally speaking  the compiler
  1544.  
  1545.           will ignore anything following the first 8 identifier characters.
  1546.  
  1547.  
  1548.  
  1549.           Examples of Identifiers:   
  1550.  
  1551.           accounts     A386XT     Income_Tax     BUDGET1990 
  1552.  
  1553.             
  1554.  
  1555.           Try  this  self-test,  the answers   are  given  at  the  end  of
  1556.  
  1557.           the  article. 
  1558.  
  1559.             
  1560.  
  1561.           Which of the following are valid identifiers: 
  1562.  
  1563.           a) FirstRun 
  1564.  
  1565.           b) Mississippi 
  1566.  
  1567.           c) Locust12 
  1568.  
  1569.           d) George Washington 
  1570.  
  1571.           e) Program 
  1572.  
  1573.           f) 123go 
  1574.  
  1575.           g) accounts.1990 
  1576.  
  1577.  
  1578.                                                                          24
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.                By the way,  reserved words, that  is words that the  Pascal
  1592.  
  1593.           language  itself uses, cannot  be used as  valid identifiers. The
  1594.  
  1595.           complete list of  Pascal reserved words  should be found in  your
  1596.  
  1597.           manual or any decent book on Pascal. 
  1598.  
  1599.             
  1600.  
  1601.                Going  back  to our  program,  the program  heading (Program
  1602.  
  1603.           hello_there;)  has  a semi-colon  at  the  end of  the  line. The
  1604.  
  1605.           program heading  does not contain  any actual commands  it simply
  1606.  
  1607.           marks the beginning of the program. Program commands come between
  1608.  
  1609.           the Pascal reserved words begin and end, they are often referred
  1610.  
  1611.           to as the  statements part of the program and each statement line
  1612.  
  1613.           is separated  by a  semi-colon(;). The  statements part   of  the
  1614.  
  1615.           program contains a  series of  instructions for  the computer  to
  1616.  
  1617.           execute.   Our example  program contains  statements designed  to
  1618.  
  1619.           write output to the screen. To write  a line of output 
  1620.  
  1621.           the   standard   output   procedure    writeln,   the   form   is
  1622.  
  1623.           writeln('textout'). 
  1624.  
  1625.  
  1626.  
  1627.                Writeln  and write  are very  similar  in what  they  do but
  1628.  
  1629.           writeln has  the advantage  of performing  a carriage  return  so
  1630.  
  1631.           your  next writeln   statement would  write out  text   on a  new
  1632.  
  1633.           line. Try   the  program   and   make sure    you understand  the
  1634.  
  1635.           differences between write  and writeln. Note that  each statement
  1636.  
  1637.           in the  statements part is separated by a semi-colon 
  1638.  
  1639.           except the  one preceding   the  reserved word  end and that  the
  1640.  
  1641.           final end in the program is followed by a period. Finally  on the
  1642.  
  1643.  
  1644.                                                                          25
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.           program  heading  line you  will  have  noticed that  there  is a
  1658.  
  1659.           comment  in curly brackets.  You can place  comments at strategic
  1660.  
  1661.           points in your  program to  add clarity. Comments  will help  you
  1662.  
  1663.           when you want   to amend you programs   after you have   not used
  1664.  
  1665.           them for  some  time they will  show what  your intention was  at
  1666.  
  1667.           the  time   you  wrote   the  program, something  you  may   have
  1668.  
  1669.           forgotten as time  goes by. The  rule is  you can place  comments
  1670.  
  1671.           at relevant points   in the program  as long as   they are placed
  1672.  
  1673.           within curly brackets.  Here are  some more examples  for you  to
  1674.  
  1675.           try: 
  1676.  
  1677.             
  1678.           program  Name_and_address;
  1679.           {  writes to  the screen  your name  and address  } 
  1680.           begin 
  1681.              writeln('My Initials Surname'); 
  1682.              writeln('Department of Computer Science'); 
  1683.              writeln('  The  University');
  1684.             {  note  the use  of  spaces  for  output  } 
  1685.              writeln('        City'); 
  1686.              writeln('         Country') 
  1687.           end. 
  1688.             
  1689.  
  1690.           Writeln is  handy for  inserting blank  lines so  that your  text
  1691.  
  1692.           output looks better 
  1693.  
  1694.           program nice_lines; 
  1695.           begin 
  1696.              writeln('Line one'); 
  1697.              writeln; { inserts a blank line } 
  1698.              writeln('Line three') 
  1699.           end. 
  1700.             
  1701.  
  1702.                Just  to get  you thinking,  write  a Pascal  program that 
  1703.  
  1704.           would produce  the following output to the screen: 
  1705.  
  1706.             
  1707.  
  1708.           'How many times have I told you, don't do that'; she said. 
  1709.  
  1710.                                                                          26
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.             
  1724.  
  1725.           Clue - watch the quotation marks!   
  1726.  
  1727.  
  1728.  
  1729.           TIP - If you are using Turbo Pascal  there is a neat routine
  1730.  
  1731.           provided to clear the screen. It can be implemented as follows: 
  1732.  
  1733.             
  1734.           program clear; 
  1735.           uses crt; { this must be here and is for turbo pascal only } 
  1736.           begin 
  1737.              clrscr;  { turbo pascal clear screen routine } 
  1738.              ........... 
  1739.              ........... 
  1740.           end. 
  1741.             
  1742.  
  1743.                I hope you have found this article helpful in the next issue
  1744.  
  1745.           I hope  to discuss  variable types  found in  Pascal, more  about
  1746.  
  1747.           top-down design  and provide  more tips.  I will  also provide  a
  1748.  
  1749.           solution to the exercise. In case you cannot wait and are pulling
  1750.  
  1751.           your hair out in frustration you can contact  me at the following
  1752.  
  1753.           Email addresses for the solution. I would also be pleased to help
  1754.  
  1755.           beginners with Pascal programing problems as well. 
  1756.  
  1757.             
  1758.  
  1759.           JANET - MCGDRKG@UK.AC.MCC.CMS 
  1760.  
  1761.           INTERNET - MCGDRKG%MCC.CMS.AC.UK@CUNYVM.CUNY.EDU 
  1762.  
  1763.           EARN/BITNET - MCGDRKG%MCC.CMS.AC.UK@UKACRL 
  1764.  
  1765.             
  1766.  
  1767.           I would  really appreciate  useful routines  for publication  and
  1768.  
  1769.           especially nice little  tricks like the clear-screen  routine for
  1770.  
  1771.           turbo pascal which would be of benefit to users at this level. 
  1772.  
  1773.             
  1774.  
  1775.  
  1776.                                                                          27
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.           Thanks for your attention - Bob Gowans. 
  1790.  
  1791.             
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.           Self Test Answers 
  1798.  
  1799.             
  1800.  
  1801.           a) Valid. 
  1802.  
  1803.           b) Valid 
  1804.  
  1805.           c) Valid 
  1806.  
  1807.           d) Invalid - there is a space character. 
  1808.  
  1809.           e) Invalid - program is a Pascal reserved word. 
  1810.  
  1811.           f) Invalid - does not start with a letter. 
  1812.  
  1813.           g) Invalid - Pascal identifiers do not allow a period. 
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.                                                                          28
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.                                       Conclusion
  1856.  
  1857.  
  1858.  
  1859.                Well, I have to  say, I'm much happier with the second issue
  1860.  
  1861.           of PNL. I'm glad I found the  time to include some code examples.
  1862.  
  1863.           I feel  it is  important to  have something  substantial for  the
  1864.  
  1865.           users  to  work with.  I  would  especially like  to  thank Craig
  1866.  
  1867.           Thurber and  Bob Gowans  for their  help by  including very  well
  1868.  
  1869.           written and  useful articles. I hope that in the future they, and
  1870.  
  1871.           others, will contribute more. It not only gives readers more than
  1872.  
  1873.           one point of  view in programming, but  it also takes a  big load
  1874.  
  1875.           off of my shoulders.
  1876.  
  1877.  
  1878.  
  1879.                I had originally planned an article  on sorting routines for
  1880.  
  1881.           this issue, but because of time  constraints I've been finding it
  1882.  
  1883.           very difficult  to proceed.  Instead of  delaying the  release of
  1884.  
  1885.           this issue further, I  have decided to go ahead  and release this
  1886.  
  1887.           issue and try to put the sorting article in a future issue.
  1888.  
  1889.  
  1890.  
  1891.                I would be a liar if I said I think the code I have provided
  1892.  
  1893.           is  fool-proof.  I've  tested  it, but  I  might  have overlooked
  1894.  
  1895.           something. If you do find a bug in the code I've provided, please
  1896.  
  1897.           let me know and I will include code fixes in following issues.
  1898.  
  1899.  
  1900.  
  1901.                My original plan  was to have more than one issue of PNL out
  1902.  
  1903.           a  month,  but   unless  I  start   getting  a  lot  of   article
  1904.  
  1905.           contributions,  that's  going   to  be   a  difficult  thing   to
  1906.  
  1907.  
  1908.                                                                          29
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.           accomplish. I'll tell you one thing that  would be really nice to
  1922.  
  1923.           have  is reviews written  by users. If  you would like  to review
  1924.  
  1925.           libraries and toolkits, feel  free to send those reviews in. I am
  1926.  
  1927.           also considering a  column called  'Bits and  Pieces' which  will
  1928.  
  1929.           have a bunch of small tips and techniques in pascal that  are too
  1930.  
  1931.           small  to deserve  articles  by themselves,  but  which would  be
  1932.  
  1933.           useful. 
  1934.  
  1935.  
  1936.  
  1937.                Another column  I would  like to  include is  a reader  mail
  1938.  
  1939.           column for comments and Q & A. 
  1940.  
  1941.  
  1942.  
  1943.                I am developing a rather large  distribution list and know I
  1944.  
  1945.           will  be racking  up pretty  hefty  phone bills  if it  gets much
  1946.  
  1947.           larger, so for the moment, here are the plans. I will only take a
  1948.  
  1949.           few more people  by node address  on the distribution list.  It's
  1950.  
  1951.           much easier for me  to send via BitNet, so I'll  be taking BitNet
  1952.  
  1953.           addresses until it gets too overbearing.  If you have a mainframe
  1954.  
  1955.           account  that is  on  BitNet, you  can pick  it up  from Simtel20
  1956.  
  1957.           either by using either of the following:
  1958.  
  1959.            TELL LISTSERV AT NDSUVM1 /PDGET PD:<MSDOS.PASCAL>PNLxxx.ZIP
  1960.  
  1961.           or
  1962.  
  1963.            TELL LISTSERV AT RPIECS /PDGET PD:<MSDOS.PASCAL>PNLxxx.ZIP
  1964.  
  1965.           where xxx is the issue #. (These are CMS commands. If you're on a
  1966.  
  1967.           Vax, the commands may  differ slightly.) It is also  available on
  1968.  
  1969.           GEnie.  I will  start putting the  FidoNet addresses,  State, and
  1970.  
  1971.           Area Code of people on the distribution list. Perhaps one of them
  1972.  
  1973.  
  1974.                                                                          30
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.           will be within local calling range of you. 
  1988.  
  1989.  
  1990.  
  1991.                What would be really  nice, is if some people out there with
  1992.  
  1993.           BitNet accounts in major cities would offer to receive a copy and
  1994.  
  1995.           spread it  around  their cities  for  me. It's  really  difficult
  1996.  
  1997.           getting a good distribution, but I'll work at it. Hopefully after
  1998.  
  1999.           a while distribution will take care of itself. i.e.  the PNL gets
  2000.  
  2001.           popular enough that it gets spread around well.
  2002.  
  2003.  
  2004.  
  2005.                Well, that  just about does it for  the second issue of PNL.
  2006.  
  2007.           Hope  it's been useful,  and like I  say and say  and say, please
  2008.  
  2009.           submit articles  and send suggestions. This newsletter is for the
  2010.  
  2011.           readers, not me. 
  2012.  
  2013.  
  2014.  
  2015.                                                 _Pete Davis
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.                                                                          31
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.                The Pascal NewsLetter is Copyrighted by Peter Davis. It
  2055.                may be freely  distributed in un-modified form,  but no
  2056.                charge whatsoever may be incurred on the recipient.
  2057.  
  2058.                The  Pascal  NewsLetter   can  be  obtained   from  the
  2059.                following locations:
  2060.  
  2061.                GEnie : General Electric Network for Information       
  2062.                        Exchange. It is located in the IBMPC filelist.
  2063.  
  2064.                Simtel: Internet address: 26.2.0.74 or Simtel20.ARPA It 
  2065.                        is located in the <MSDOS.PASCAL> directory.
  2066.  
  2067.                Programmer's Forum : This is the home of the PNL. Each
  2068.                                     issue can be found in the MAG     
  2069.                                     directory from the main area.
  2070.                                     The number is on the title page.
  2071.  
  2072.                If  you  would  like  to receive  back  issues  of  PNL
  2073.                directly  from  me,  send  a  diskette  and  $2.00  for
  2074.                shipping. Don't forget to include your address.
  2075.                Send your order to:
  2076.                   Peter Davis
  2077.                   4851 Brandywine St. NW
  2078.                   Washington, DC   20016
  2079.  
  2080.                If you are  a SysOp that  will regularly carry PNL  and
  2081.                would like to have your  bulletin board listed as such,
  2082.                here, send me a message either by postal mail or at one
  2083.                of the electronic  addresses given  on the title  page,
  2084.                with  your bulletin  board's  name, phone  number, your
  2085.                name, maximum baud rate, and a  description of up to 60
  2086.                characters of your bbs.
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.                                                                     32
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.                                   Distribution List
  2120.  
  2121.                The following is the phone numbers to  bulletin boards known
  2122.           to carry  PNL. If you would  like your bulletin  board's name and
  2123.           number  added to  or deleted  from this  list, please  send  me a
  2124.           message at one of my many addresses.
  2125.  
  2126.           The Programmer's Forum ................. Phone: (202) 966-3647 
  2127.           The Programmer's Forum is the home of the PNL.
  2128.  
  2129.           The Bored .............................. Phone: (512) 303-0471
  2130.  
  2131.           Classic City ........................... Phone: (404) 548-0726
  2132.  
  2133.           Theive's World ......................... Phone: (713) 463-8053
  2134.  
  2135.           Hippocampus ............................ Phone: (203) 484-4621
  2136.  
  2137.           Rogers State College BBS ............... Phone: (918) 341-8982
  2138.  
  2139.           The Foxtrot BBS ........................ Phone: (404) 793-2673
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.                                                                          33
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.